package org.amphiprion.descentv2assistant.adapter;

import java.util.LinkedHashMap;

import org.amphiprion.descentv2assistant.R;
import org.amphiprion.descentv2assistant.ui.fragment.EncounterHeroListFragment;
import org.amphiprion.descentv2assistant.ui.fragment.EncounterMonsterListFragment;
import org.amphiprion.descentv2assistant.ui.fragment.EncounterQuestListFragment;
import org.amphiprion.descentv2assistant.ui.fragment.HeroListFragment;
import org.amphiprion.descentv2assistant.ui.fragment.MonsterListFragment;
import org.amphiprion.descentv2assistant.ui.views.TitleProvider;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class GameSessionViewPagerAdapter extends FragmentPagerAdapter implements TitleProvider {
	private final LinkedHashMap<String, Fragment> mScreens;

	public GameSessionViewPagerAdapter(FragmentActivity activity, FragmentManager fm) {
		super(fm);
		this.mScreens = new LinkedHashMap<String, Fragment>();
		// if (App.isPhone(activity)) {
		// this.mScreens.put(activity.getString(R.string.title_tab_discovery), DiscoveryFragment.newInstance());
		// }
		this.mScreens.put(activity.getString(R.string.encounter_quest_tab_title), EncounterQuestListFragment.newInstance());
		this.mScreens.put(activity.getString(R.string.encounter_hero_tab_title), EncounterHeroListFragment.newInstance());
		this.mScreens.put(activity.getString(R.string.encounter_tab_title), EncounterMonsterListFragment.newInstance());
		// this.mScreens.put(activity.getString(R.string.title_tab_recent), RecentEpisodeListFragment.newInstance());

	}

	@Override
	public Fragment getItem(int paramInt) {
		return this.mScreens.values().toArray(new Fragment[this.mScreens.size()])[paramInt];
	}

	@Override
	public String getTitle(int paramInt) {
		return this.mScreens.keySet().toArray(new String[this.mScreens.size()])[paramInt];
	}

	@Override
	public int getCount() {
		return this.mScreens.size();
	}

	public void doFilter(int currentItem) {
		Fragment f = getItem(currentItem);
		if (f instanceof MonsterListFragment) {
			((MonsterListFragment) f).doFilter();
		} else if (f instanceof HeroListFragment) {
			((HeroListFragment) f).doFilter();
		}

	}

	public void addMonster(int currentItem) {
		Fragment f = getItem(currentItem);
		if (f instanceof EncounterMonsterListFragment) {
			((EncounterMonsterListFragment) f).addMonster();
		} else if (f instanceof EncounterHeroListFragment) {
			((EncounterHeroListFragment) f).addHero();
		} else if (f instanceof EncounterQuestListFragment) {
			((EncounterQuestListFragment) f).addQuest();
		}
	}

}
